package com.demo.controller;

import com.demo.entity.Patient;
import com.demo.entity.PatientTransition;
import com.demo.response.Result;
import com.demo.service.IPatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 病患信息表 前端控制器
 *
 * @author zm
 * @since 2020-11-26
 */
@RestController
@Api(tags = "病人接口类")
@RequestMapping("/patient")
public class PatientController {
    @Autowired
    IPatientService patientService;


    @ApiOperation(value = "病患信息列表", tags = {"病人接口类", "v20210421更新"})
    @ApiImplicitParams({@ApiImplicitParam(name = "wardId", value = "病区映射编码"),
    @ApiImplicitParam(name = "patientId", required = false, value = "病人id号")})
    @GetMapping("/patientList")
    public Result patientList(@RequestParam(name = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                              @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                              @RequestParam(name = "admissionId", required = false) String admissionId,
                              @RequestParam(name = "deptType", required = false) Integer deptType,
                              @RequestParam(name = "patientId", required = false) String patientId,
                              @RequestParam(name = "vestType", required = false) Integer vestType,
                              @RequestParam(name = "status", required = false) Integer status,
                              @RequestParam(name = "deptSn", required = false) Integer deptSn,
                              @RequestParam(name = "wardId", required = false) String wardId) {
        return patientService.patientList(pageNumber, pageSize, admissionId, deptType, patientId, vestType, status, deptSn, wardId);
    }

    @ApiOperation("新增病患")
    @PostMapping("/addPatient")
    public Result addPatient(@RequestBody @Validated Patient patient) throws Exception {
        return Result.success(patientService.addPatient(patient));
    }

    @ApiOperation("患者详情")
    @GetMapping({"/selectPatientDesc"})
    public Result selectPatientDesc(@RequestParam(name = "patientId", required = false) Integer patientId) throws Exception {
        return Result.success(patientService.selectPatientDesc(patientId));
    }

    @ApiOperation(value = "患者病例变化", tags = {"v20210507更新", "v20210513更新"})
    @ApiImplicitParams({@ApiImplicitParam(name = "his_patient_id", value = "HIS系统病人编号"),
    @ApiImplicitParam(name = "status", value = "状态，诊断时间 1 新入 2 术后 3 分娩 4 出院"),
    @ApiImplicitParam(name = "is_transition", required = true, value = "是否转科"),
    @ApiImplicitParam(name = "admission_id", value = "住院号"),
    @ApiImplicitParam(name = "ward_id", value = "转往科室病区编号"),
    @ApiImplicitParam(name = "deptSn", value = "转往科室编号，转科情况下必填"),
    @ApiImplicitParam(name = "bed_id", value = "转往创号"),
    @ApiImplicitParam(name = "medical_leader", value = "转往医疗组长工号"),
    @ApiImplicitParam(name = "medical_leader_name", value = "转往医疗组长姓名"),
    @ApiImplicitParam(name = "doctor_in_charge", value = "转往主管医生工号"),
    @ApiImplicitParam(name = "doctor_in_charge_name", value = "转往主管医生姓名"),
    @ApiImplicitParam(name = "head_nurse", value = "转往护士长工号"),
    @ApiImplicitParam(name = "head_nurse_name", value = "转往护士长姓名"),
    @ApiImplicitParam(name = "nurse_in_charge", value = "转往主管护士工号"),
    @ApiImplicitParam(name = "nurse_in_charge_name", value = "转往主管护士姓名"),
    @ApiImplicitParam(name = "hospital_disttrict_name", value = "转往病区名称"),
    @ApiImplicitParam(name = "hospital_disttrict_id", value = "转往病区 id")})
    @GetMapping({"/changPatientStatus"})
    public Result changePatientStatus(@RequestParam(name = "his_patient_id") Integer his_patient_id,
                                      @RequestParam(name = "status", required = false) Integer status,
                                      @RequestParam(name = "is_transition") Integer is_transition,
                                      @RequestParam(name = "admission_id", required = false) String admission_id,
                                      @RequestParam(name = "ward_id", required = false) Integer ward_id,
                                      @RequestParam(name = "deptSn", required = false) Integer deptSn,
                                      @RequestParam(name = "bed_id", required = false) String bed_id,
                                      @RequestParam(name = "medical_leader", required = false) Integer medical_leader,
                                      @RequestParam(name = "medical_leader_name", required = false) String medical_leader_name,
                                      @RequestParam(name = "doctor_in_charge", required = false) Integer doctor_in_charge,
                                      @RequestParam(name = "doctor_in_charge_name", required = false) String doctor_in_charge_name,
                                      @RequestParam(name = "head_nurse", required = false) Integer head_nurse,
                                      @RequestParam(name = "head_nurse_name", required = false) String head_nurse_name,
                                      @RequestParam(name = "nurse_in_charge", required = false) Integer nurse_in_charge,
                                      @RequestParam(name = "nurse_in_charge_name", required = false) String nurse_in_charge_name,
                                      @RequestParam(name = "hospital_disttrict_name", required = false) String hospital_disttrict_name,
                                      @RequestParam(name = "hospital_disttrict_id", required = false) Integer hospital_disttrict_id) throws Exception {
        PatientTransition patientTransition = new PatientTransition();
        if (is_transition.intValue() == 1) { // 转科
            patientTransition.setAdmissionId(admission_id);
            patientTransition.setWardId(ward_id);
            patientTransition.setBedId(bed_id);
            patientTransition.setHisPatientId(his_patient_id);
            patientTransition.setMedicalLeader(medical_leader);
            patientTransition.setMedicalLeaderName(medical_leader_name);
            patientTransition.setDoctorInCharge(doctor_in_charge);
            patientTransition.setMedicalLeaderName(doctor_in_charge_name);
            patientTransition.setDoctorInCharge(doctor_in_charge);
            patientTransition.setDoctorInChargeName(doctor_in_charge_name);
            patientTransition.setHeadNurse(head_nurse);
            patientTransition.setDoctorInChargeName(doctor_in_charge_name);
            patientTransition.setNurseInCharge(nurse_in_charge);
            patientTransition.setNurseInChargeName(nurse_in_charge_name);
            patientTransition.setHospitalDisttrictName(hospital_disttrict_name);
            patientTransition.setHospitalDisttrictId(hospital_disttrict_id);
            patientTransition.setDeptSn(deptSn);
        }
        return patientService.changPatientStatus(his_patient_id, status, is_transition, patientTransition);
    }

    @ApiOperation(value = " 患者档案信息", tags = {"v20210427更新"}, notes = "患者编号或HIS 系统病人编号必须写一个")
    @GetMapping({"/patientArchives"})
    @ApiImplicitParams({@ApiImplicitParam(name = "his_patient_id", value = "HIS系统病人编号"), @ApiImplicitParam(name = "patient_id", value = "VTE系统的患者编码")})
    public Result patientArchives(@RequestParam(name = "his_patient_id", required = false) Integer his_patient_id, @RequestParam(name = "patient_id", required = false) Integer patient_id) throws Exception {
        return Result.success(patientService.getPatientArchives(his_patient_id, patient_id));
    }

}
